<template>
	<view>
		<view class="logo">
			
		</view>
		<u-form borderBottom class="form">
			<u-form-item>
				<u--input prefixIcon="account" prefixIconStyle="font-size: 22px;color: #909399" type="text"
					v-model="formData.account" placeholder="请输入账号/手机号码" ></u--input>
			</u-form-item>
			<u-form-item>
				<u--input prefixIcon="lock" prefixIconStyle="font-size: 22px;color: #909399" type="password"
					v-model="formData.password" placeholder="请输入密码" ></u--input>
			</u-form-item>
			<u-form-item>
				<navigator url="/pages/forget_pwd/forget_pwd" hover-class="none">
					<view class="border-l border-solid border-0 border-light pl-3 text-muted leading-4 ml-3">
						忘记密码？
					</view>
				</navigator>
			</u-form-item>
			<view class="u-p-30">
				<u-button type="primary" shape="circle" @click="handleLogin()">
					登 录
				</u-button>
			</view>
			
		</u-form>
	</view>
</template>

<script>
	import {
		apiLogin
	} from "@/api/api.js"
	import {
		mapActions
	} from 'vuex';
	export default {
		data() {
			return {
				name: "",
				formData: {
					scene: 1,
					account: '13427833041',
					password: '111111',
					code: ''
				},
				border: false

			}
		},
		onShow() {
			// uni.setStorageSync("tt", "333");
			// let t = uni.getStorageSync("tt");
			// console.log("token",t);
		},
		methods: {
			...mapActions(['loginAction']),
			async handleLogin() {
				if (this.formData.account.length < 5) {
					uni.showToast({
						title: '请输入账号',
						icon: 'none',
						duration: 2000
					})
					return;
				}
				uni.showLoading({
					title: '加载中...'
				});
				let data = {
					account: this.formData.account,
					password: this.formData.password
				};

				await apiLogin(data).then((res) => {
					uni.hideLoading();
					console.log(res);
					// if(res.code==1){
					// const {
					// 	token,
					// 	user
					// } = res
					this.loginAction({
						token: res.token,
						user: res.user
					});
					// uni.setStorageSync("user", JSON.stringify(res.user));
					// uni.setStorageSync("token", res.token);

					uni.showToast({
						title:'登录成功',
						duration:2000
					});
					
					
					
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/user/user'
						})
					}, 1000)

					// }else{
					// 	uni.showToast({
					// 		title: res.msg,
					// 		icon: 'none'
					// 	})
					// }

				}).catch(() => {

				})



			},


		}
	}
</script>

<style>
	.form {
		padding: 60rpx;
	}
	
	.logo{
		width: 200rpx;
		height: 200rpx;
		margin: 0 auto;
	}
</style>